package com.example.project.model.bo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 分页参数
 * Created by Administrator on 2016/5/13.
 */
public class OutPagingParam {
    /**
     * 第页多少行
     */
    public int prepage=25;
    /**
     * 当前页
     */
    public int page=1;

    int totalNumber=0;

    //每个分页展示多少个
    public int pageNumber=10;

    public int getTotalNumber() {
        return totalNumber;
    }

    public void setTotalNumber(int totalNumber) {

        int totalPageNum = (this.getTotalNumber()  +  this.getPrepage()  - 1) / this.getPrepage();
        //如果当前页大于总页数
        if(this.getPage()>totalPageNum){
            //则设置当前页为未尾页
            this.setPage(totalPageNum);
        }
        this.totalNumber = totalNumber;
    }

    public int getPage() {
        if(page<=0){
            page=1;
        }
        if(this.getTotalPage()<page){
            page=this.getTotalPage();
        }
        return page;
    }

    public int getOffset(){
        return (getPage()-1)*getPrepage();
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPrepage() {
        if(prepage<=0){
            prepage=25;
        }
        return prepage;
    }

    public void setPrepage(int prepage) {
        this.prepage = prepage;
    }

    //
    public int getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

    //获取总数据页面数
    public int getTotalPage(){

        int totalPageNum = this.getTotalNumber() / this.getPrepage()+(this.getTotalNumber() % this.getPrepage()>0?1:0);

        return totalPageNum;

    }

    //获取总版页数
    public int getTotalPageNumber(){

        int totalPageNumber =0;

        totalPageNumber=(this.getTotalPage()  / this.getPageNumber())+(this.getTotalPage() % this.getPageNumber()>0?1:0);

//        if(getTotalPage()>getPageNumber()){
//           //(this.getTotalPage()  +  this.getPageNumber()  - 1) / this.getPageNumber();
//        }
        // int totalPageNumber =
        return totalPageNumber;
    }

    //获取当前第几版
    public int getCurrentPageNumber(){

        int currentPageNumber = (this.getPage()  +  this.getPageNumber()  - 1) / this.getPageNumber();

        return currentPageNumber;
    }

    //获取开始页
    public int getStartPage(){

        int StartPage=this.getCurrentPageNumber()>1?((this.getCurrentPageNumber()-1)*this.getPageNumber())+1:1;
        return StartPage;
    }

    //获取结束页
    public int getEndPage(){
        int endPage=this.getCurrentPageNumber()==this.getTotalPageNumber()||this.getTotalPageNumber()==0?this.getTotalPage():this.getCurrentPageNumber()*this.getPageNumber();
        return endPage;
    }

    //获取当前页输出多少行
    public int getTotalOutPutNumber(){
        int totalOutPutNumber=this.getEndPage()-this.getStartPage()+1;
        return totalOutPutNumber;
    }


    //是否需要往前
    public boolean isGotoFirst(){
        //如果当前页面大于总分页数除以每页分页按钮数据时，需要往前
        if(this.getCurrentPageNumber()>1){
            return true;
        }else{
            return false;
        }
    }

    public boolean isGotoLast(){
        //如果当前页面大于总分页数除以每页分页按钮数据时，需要往前
        if(this.getCurrentPageNumber()<this.getTotalPageNumber()){
            return true;
        }else{
            return false;
        }
    }
    List<Map<String,String>> dataArray=new ArrayList<>();

    public List<Map<String, String>> getDataArray() {
        for(int i=1,k=this.getStartPage();i<=getTotalOutPutNumber()&&k<=this.getEndPage();i++,k++){
            Map<String,String> map= new HashMap<String,String>();
            map.put("pageNumber",k+"");
            if(k==this.getPage()) {
                map.put("active", "1");
            }else{
                map.put("active", "0");
            }
            dataArray.add(map);
        }
        return dataArray;
    }

    public void setDataArray(List<Map<String, String>> dataArray) {

        this.dataArray = dataArray;
    }

//    public List<Map<String,String>> getOutDatas(){
//
//        for(int i=1,k=this.getStartPage();i<=getTotalOutPutNumber()&&k<=this.getEndPage();i++,k++){
//            Map<String,String> map= new HashMap<String,String>();
//            map.put("pageNumber",k+"");
//            if(k==this.getPage()) {
//                map.put("active", "1");
//            }else{
//                map.put("active", "0");
//            }
//        }
//        return dataArray;
//    }
}
